home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Fixation 1.3
/
blit.c
next >
Wrap
Text File
|
1995-10-14
|
5KB
|
150 lines
// blit.c
#include "blit.h"
#include "error.h"
// safe and mild, assumes both pixmaps same size
//
// assumes:
// bounds start at 0, 0 of pixmaps
void copydouble(PixMapPtr srcpm, PixMapPtr dstpm, Rect *srcRect, Rect *dstRect)
{
long *src, *dst, dest;
long srcrb, dstrb, soffset, doffset, loopoffset;
int offset, rowlongs, loop;
Rect *srcbounds, *dstbounds, *r;
int starty, endy, startx, endx, padding;
srcbounds = &srcpm->bounds;
dstbounds = &dstpm->bounds;
// find vertical indices
r = srcRect; // should be same, so don't matter none
starty = r->top; endy = r->bottom;
if (starty < 0) starty = 0;
if (endy >= srcbounds->bottom) endy = srcbounds->bottom - 1;
if (endy <= 0) return;
if (starty >= srcbounds->bottom) return;
// find horizontal indices
// make sure they align to 32-bits (assuming 8-bit depth)
startx = r->left;
if (startx < 0) startx = 0;
if (startx >= srcbounds->right) return;
startx = (startx >> 2) << 2; // clear 2 least-significant bits
endx = r->right;
if (endx <= 0) return;
if (endx > srcbounds->right) endx = srcbounds->right;
padding = endx & 3;
if (padding)
endx += 4 - padding; // endx is now aligned
rowlongs = (endx - startx) >> 2;
// rect should now be clipped
src = (long *) srcpm->baseAddr;
dst = (long *) dstpm->baseAddr;
srcrb = srcpm->rowBytes & 0x3fff;
dstrb = dstpm->rowBytes & 0x3fff;
verify(srcrb == dstrb);
// set up offsets
soffset = startx;
soffset += starty * srcrb;
src = (long *) ((long) src + soffset);
doffset = startx;
doffset += starty * dstrb;
dst = (long *) ((long) dst + doffset);
// prepare for loop
loop = endy - starty;
loopoffset = srcrb - (rowlongs << 2);
// copy the pix
while (loop-- > 0) {
switch (rowlongs) {
case 24: *dst++ = *src++;
case 23: *dst++ = *src++;
case 22: *dst++ = *src++;
case 21: *dst++ = *src++;
case 20: *dst++ = *src++;
case 19: *dst++ = *src++;
case 18: *dst++ = *src++;
case 17: *dst++ = *src++;
case 16: *dst++ = *src++;
case 15: *dst++ = *src++;
case 14: *dst++ = *src++;
case 13: *dst++ = *src++;
case 12: *dst++ = *src++;
case 11: *dst++ = *src++;
case 10: *dst++ = *src++;
case 9: *dst++ = *src++;
case 8: *dst++ = *src++;
case 7: *dst++ = *src++;
case 6: *dst++ = *src++;
case 5: *dst++ = *src++;
case 4: *dst++ = *src++;
case 3: *dst++ = *src++;
case 2: *dst++ = *src++;
case 1: *dst++ = *src++;
case 0: break;
// default: DebugPrint(srcRect->right - srcRect->left); verify(false);
}
dst = (long *) (((long) dst) + loopoffset);
src = (long *) (((long) src) + loopoffset);
}
}
static void copyslick(PixMapPtr srcpm, PixMapPtr dstpm, Rect *srcRect, Rect *dstRect)
{
long *src, *dst, dest;
long srcrb, dstrb;
int offset;
Rect *srcbounds, *dstbounds;
srcbounds = &srcpm->bounds;
dstbounds = &dstpm->bounds;
// check for rect situations that should do nuttin'
if ((srcRect->right < 0) || (srcRect->left >= srcbounds->right) ||
(srcRect->bottom < 0) || (srcRect->top >= srcbounds->bottom) ||
(dstRect->right < 0) || (dstRect->left >= dstbounds->right) ||
(dstRect->bottom < 0) || (dstRect->top >= dstbounds->bottom))
return;
// perform simple clipping
if (srcRect->left < 0) {
offset = -srcRect->left;
srcRect->left += offset; dstRect->left += offset;
}
if (srcRect->top < 0) {
offset = -srcRect->top;
srcRect->top += offset; dstRect->top += offset;
}
offset = srcRect->right - srcbounds->right;
if (offset > 0)
srcRect->right -= offset; dstRect->right -= offset;
offset = srcRect->bottom - srcbounds->bottom;
if (offset > 0)
srcRect->bottom -= offset; dstRect->bottom -= offset;
// rects should now be clipped
src = (long *) srcpm->baseAddr;
dest = (long) dstpm->baseAddr;
srcrb = srcpm->rowBytes & 0x3fff;
dstrb = dstpm->rowBytes & 0x3fff;
// dest += r->left;
// dest += r->top * dstrb;
dst = (long *) dest;
// copy the pix
*dst = *src;
dst = (long *) ((long) dst + dstrb);
src = (long *) ((long) src + srcrb);
}